<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="db.Album"%>

<%@page import="db.User"%>
<%@page import="db.DbUtils"%>
<%@page import="org.hibernate.Session"%>
<%@page import="java.util.Arrays"%>
<%@page import="utils.AlbumsComparator"%>
<%@page import="java.util.Collections"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%><html
	xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="my" tagdir="/WEB-INF/tags"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.text.DateFormat"%>
<%@page import="db.Picture"%>
<%@page import="presentation.Get16ImagesBean"%>
<head>
<link rel="stylesheet" type="text/css" href="css/styleGallery.css" />
<title>Добави снимка</title>
</head>

<body id="bd">

<div id="container"><my:header /> <%
 	Long userid = (Long) session.getAttribute("userid");
	if (userid == null) {
	%>
	<c:redirect url="Home.jsp" > </c:redirect>
	<%
}
 	if (userid != 0) {
 %> <my:menulogin />

<div id="midcontainer">
<%
	List<Album> albums = DbUtils.getUserAlbums(DbUtils.startSession(), userid);
	
		if (albums.size() > 0) {
			Collections.sort(albums, new AlbumsComparator());		
%>
<table width="100%" align="center">
<tr>
<td width="50%"> 
	<div id="uploadsite">
		<form name="myform" action="UploadServlet" method="post" enctype="multipart/form-data" id="form1">
			<div id="labelupl">Прикачване на снимки</div>
			<table>
			<tr>
			<td align="left">
			Пациент:
			</td>
			<td align="left">
			<select id="combo" class="box" name="albumid" title="albumid">
<%
			for (int i = 0; i < albums.size(); i++) {
						Album album = albums.get(i);
%>
				<option value="<%=album.getAlbumId()%>"><%=album.getAlbumName()%></option>
<%
			}
%>
			</select> 
			</td>
			</tr>
			<tr>
			<td align="left">
			Име:
			</td>
			<td align="left">
			<%
				Date date = new Date(System.currentTimeMillis());
				SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy" );
				
			%>
			<input class="box" type="text" name="title" value="<%=sdf.format(date) %>"/>
			</td>
			</tr>
			<tr>
			<td align="left">
			Снимка:
			</td>
			<td>
			<input class="box" name="user_file" type="file" value="Избери" />
			</td>
			</tr>
			</table>
			<div id="labelupl"><input style="float: none" class="button1" type="submit" value="Добави" /></div>
		</form>
	</div>
</td>	
<td width="50%">
	<div id="newalbum">
          <form action="AddAlbumServlet" id="form1" method="post">
                <div id="labelupl">Създаване на нов Пациент</div>
               <!--  Албум родител:<br />
                	<select class="box" name="parent_id" title="parent_id">
                	<option value="">-- Без родител --</option>
<%
			for (int i = 0; i < albums.size(); i++) {
						Album album = albums.get(i);
%>
				<option value="<%=album.getAlbumId()%>"><%=album.getAlbumName()%></option>
<%
			}
%>
			</select> --> <br />
                
                
                    Име:<br />
                    <input id="upload" name="album_name" type="text" maxlength="20" /><br /><br />
                   <div id="labelupl">
                   	<input style="float: none" class="button1" type="submit" value="Cъздай" />
                   </div>
                   <input type="hidden" name="refer" value="addpic.jsp" />
            </form>
	</div>
	</td>
</tr>
</table>
<%
	} else {
%> 
	<h1 align="center">Нямате нито един пациент! </h1>
	<h2 align="center">Моля създайте пациент за да може да добавите снимка за него.</h2>
	<div id="uploadsite">
          <form action="AddAlbumServlet" id="form1" method="post">
                <div id="labelupl">Създаване на нов Пациент</div>
                    Име:<br>
                    <input id="upload" name="album_name" type="text" maxlength="20" />
                   <div id="labelupl">
                   	<input style="float: none" class="button1" type="submit" value="Cъздай" />
                   </div>
                   <input type="hidden" name="refer" value="addpic.jsp" />
            </form>
	</div>

<%
 	}
 %>
 <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 <br /><br /><br />
</div>

<%
	} else {
%> <my:menulogout />
<div id="midcontainer"></div>
<%
	}
%> <my:footer />
</body>
</html>